package com.xu.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @author anan
 * @create 2022-01-13 16:21
 */
@Configuration
@EnableSwagger2
public class Swagger2 {

    //访问地址 :http://localhost:8088/swagger-ui.html
    //http://localhost:8088/doc.html

    @Bean
    public Docket createDocket(){
        Docket docket = new Docket(DocumentationType.SWAGGER_2);
        docket.apiInfo(createApiInfo());
        docket.select().apis(RequestHandlerSelectors.basePackage("com.xu.controller")).paths(PathSelectors.any()).build();
        return docket;
    }

    private ApiInfo createApiInfo(){
        ApiInfoBuilder apiInfoBuilder = new ApiInfoBuilder();
        apiInfoBuilder.title("天天吃货 电商平台接口api");
        apiInfoBuilder.contact(new Contact("xu","https://www.baidu.com", "https://804236948@qq.com"));
        apiInfoBuilder.description("专门为天天吃货提供的api文档");
        apiInfoBuilder.version("1.0.1");
        apiInfoBuilder.termsOfServiceUrl("https://www.baidu.com");
        return apiInfoBuilder.build();
    }
}
